/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Exploder.java]
 * Creation Date        [22-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_03_game.tankwar_local.version_6;

import java.awt.Color;
import java.awt.Graphics;

/**
 * 爆炸
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Exploder {

	/** 爆炸产生的坐标 */
	private int x = 0;
	private int y = 0;

	/** 爆炸是否存在 */
	private boolean live = true;

	int[] diameters = { 3, 5, 7, 9, 13, 17, 21, 25, 32, 39, 45, 30, 20, 10, 5 };
	int step = 0;

	private final MainFrame client;

	public Exploder(int x, int y, MainFrame client) {
		super();
		this.x = x;
		this.y = y;
		this.client = client;
	}

	/**
	 * 绘制爆炸效果
	 * 
	 * @param g
	 */
	public void paint(Graphics g) {
		// 当爆炸消失时停止绘制
		if (!live) {
			client.exploders.remove(this);
			return;
		}

		// 如果step等于直径数组的长度, 表示绘制完成
		if (step == diameters.length) {
			live = false;
			step = 0;
			return;
		}

		Color color = g.getColor();
		g.setColor(Color.ORANGE);
		g.fillOval(x, y, diameters[step], diameters[step]);
		g.setColor(color);
		step++;
	}
}
